<html>
<head><meta charset="utf-8"><title>unused const params · project-const-generics · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/index.html">project-const-generics</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/unused.20const.20params.html">unused const params</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="216487640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/unused%20const%20params/near/216487640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/unused.20const.20params.html#216487640">(Nov 12 2020 at 15:59)</a>:</h4>
<p>Type parameters which are not referenced are forbidden, so the following causes in error:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Foo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
</code></pre></div>



<a name="216487685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/unused%20const%20params/near/216487685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/unused.20const.20params.html#216487685">(Nov 12 2020 at 15:59)</a>:</h4>
<p>we do however allow this with const params</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Bar</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
</code></pre></div>



<a name="216487837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/unused%20const%20params/near/216487837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/unused.20const.20params.html#216487837">(Nov 12 2020 at 16:00)</a>:</h4>
<p>What are the reasons for doing so?</p>



<a name="216487909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/unused%20const%20params/near/216487909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/unused.20const.20params.html#216487909">(Nov 12 2020 at 16:00)</a>:</h4>
<p>what i can think of:</p>



<a name="216488155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/unused%20const%20params/near/216488155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/unused.20const.20params.html#216488155">(Nov 12 2020 at 16:02)</a>:</h4>
<ul>
<li>const params are not concerned about variances, so not using <code>PhantomData</code> doesn't mean that we can end up with the wrong variance and unsoundness</li>
</ul>



<a name="216488317"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/unused%20const%20params/near/216488317" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/unused.20const.20params.html#216488317">(Nov 12 2020 at 16:03)</a>:</h4>
<ul>
<li>unlike types, const params are often expected to only change the behavior, not the content of a type. So having to always use <code>PhantomData</code> is more annoying than helpful</li>
</ul>



<a name="216489951"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/unused%20const%20params/near/216489951" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/unused.20const.20params.html#216489951">(Nov 12 2020 at 16:13)</a>:</h4>
<p>Yes, the reason that type parameters are disallowed is because their behaviour with respect to variance in that case may be surprising. Const parameters have no such issue, so we allow them.</p>



<a name="216490158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/unused%20const%20params/near/216490158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/unused.20const.20params.html#216490158">(Nov 12 2020 at 16:14)</a>:</h4>
<p>Similarly, we should permit use of const generic parameters even from parents, though we currently don't (see <a href="https://github.com/rust-lang/rust/issues/61414">https://github.com/rust-lang/rust/issues/61414</a>).</p>



<a name="216490256"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/unused%20const%20params/near/216490256" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/unused.20const.20params.html#216490256">(Nov 12 2020 at 16:14)</a>:</h4>
<p>Though that can obviously be left for a later date.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>